package com.example.demo.common.api;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;

/**
 * @Author: csj
 * @Date: 2024/4/7 16:37
 * @Description:
 */
@Data
@NoArgsConstructor
@ToString
public class ResponseData<T> implements Serializable {
    private int code;
    /**
     * 响应提示消息
     */
    private String msg;
    /**
     * 响应数据
     */
    private T data;

    private String jwt;

    public ResponseData(ResultCodeEnum resultCodeEnum, T data) {
        this.code = resultCodeEnum.getCode();
        this.msg = resultCodeEnum.getMsg();
        this.data = data;
    }

    public ResponseData(ResultCodeEnum resultCodeEnum, T data,String jwt) {
        this.code = resultCodeEnum.getCode();
        this.msg = resultCodeEnum.getMsg();
        this.data = data;
        this.jwt=jwt;
    }

    public ResponseData(ResultCodeEnum resultCodeEnum) {
        this.code = resultCodeEnum.getCode();
        this.msg = resultCodeEnum.getMsg();
    }

    public ResponseData(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResponseData(T data) {
        this(ResultCodeEnum.SUCCESS, data);
    }

    public static ResponseData ok(Object data) {
        ResponseData resultVO = new ResponseData(ResultCodeEnum.SUCCESS, data);
        return resultVO;
    }

    public static ResponseData ok(Object data,String jwt) {
        ResponseData resultVO = new ResponseData(ResultCodeEnum.SUCCESS, data,jwt);
        return resultVO;
    }

    public static ResponseData ok() {
        ResponseData resultVO = new ResponseData(ResultCodeEnum.SUCCESS);
        return resultVO;
    }

    public static ResponseData error(ResultCodeEnum resultCodeEnum) {
        ResponseData resultVO = new ResponseData(resultCodeEnum);
        return resultVO;
    }

    public static ResponseData error(int code, String msg) {
        ResponseData resultVO = new ResponseData(code, msg);
        return resultVO;
    }
    public static ResponseData error(ResultCodeEnum resultCodeEnum, Object data) {
        ResponseData resultVO = new ResponseData(resultCodeEnum, data);
        return resultVO;
    }

    public static ResponseData ok(ResultCodeEnum resultCodeEnum, String data) {
        ResponseData resultVO = new ResponseData(resultCodeEnum, data);
        return resultVO;
    }
}
